/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.opgea.qms.domain.entities;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Ramesh
 */
@Entity
@Table(name = "token")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Token.findAll", query = "SELECT t FROM Token t"),
    @NamedQuery(name = "Token.findById", query = "SELECT t FROM Token t WHERE t.id = :id"),
    @NamedQuery(name = "Token.findByTokenNo", query = "SELECT t FROM Token t WHERE t.tokenNo = :tokenNo"),
    @NamedQuery(name = "Token.findAllByCompanyId", query = "SELECT t FROM Token t WHERE t.company.id = :companyId and t.tokenDate = :tokenDate"),
    @NamedQuery(name = "Token.findAllByCompanyIdAndStatus", query = "SELECT t FROM Token t WHERE t.company.id = :companyId and t.tokenDate = :tokenDate and t.tokenDetails.tokenStatus = :tokenStatus")
})
public class Token implements Serializable {
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Long id;
    
    @Basic(optional = false)
    @Column(name = "tokenNo")
    private Integer tokenNo;
    
    @Basic(optional = false)
    @Column(name = "tokenDate")
    @Temporal(TemporalType.DATE)
    private Date tokenDate;
    
    @JoinColumn(name = "company_id", referencedColumnName = "id")
    @ManyToOne(fetch= FetchType.EAGER)
    private Company company;
    
    @OneToMany(mappedBy = "token")
    private List<CurrentToken> currentTokenList;
    
    @JoinColumn(name = "tokendetails_id", referencedColumnName = "id")
    @OneToOne(mappedBy = "token", cascade= CascadeType.REFRESH)
    private TokenDetails tokenDetails;
    

    public Token() {
    }

    public Token(Long id) {
        this.id = id;
    }

    public Token(Long id, Integer tokenNo) {
        this.id = id;
        this.tokenNo = tokenNo;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Integer getTokenNo() {
        return tokenNo;
    }

    public void setTokenNo(Integer tokenNo) {
        this.tokenNo = tokenNo;
    }

    public Date getTokenDate() {
        return tokenDate;
    }

    public void setTokenDate(Date tokenDate) {
        this.tokenDate = tokenDate;
    }

    public Company getCompany() {
        return company;
    }

    public void setCompany(Company company) {
        this.company = company;
    }

    public List<CurrentToken> getCurrentTokenList() {
        return currentTokenList;
    }

    public void setCurrentTokenList(List<CurrentToken> currentTokenList) {
        this.currentTokenList = currentTokenList;
    }

    public TokenDetails getTokenDetails() {
        return tokenDetails;
    }

    public void setTokenDetails(TokenDetails tokenDetails) {
        this.tokenDetails = tokenDetails;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Token)) {
            return false;
        }
        Token other = (Token) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Token{" + "id=" + id + ", tokenNo=" + tokenNo + ", tokenDate=" + tokenDate + '}';
    }

       
}
